package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZxbPassword;
import com.ruoyi.system.service.IZxbPasswordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账户密码管理Controller
 * 
 * @author ruoyi
 * @date 2022-10-11
 */
@RestController
@RequestMapping("/system/password")
public class ZxbPasswordController extends BaseController
{
    @Autowired
    private IZxbPasswordService zxbPasswordService;

    /**
     * 查询账户密码管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:password:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZxbPassword zxbPassword)
    {
        startPage();
        List<ZxbPassword> list = zxbPasswordService.selectZxbPasswordList(zxbPassword);
        return getDataTable(list);
    }

    /**
     * 导出账户密码管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:password:export')")
    @Log(title = "账户密码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxbPassword zxbPassword)
    {
        List<ZxbPassword> list = zxbPasswordService.selectZxbPasswordList(zxbPassword);
        ExcelUtil<ZxbPassword> util = new ExcelUtil<ZxbPassword>(ZxbPassword.class);
        util.exportExcel(response, list, "账户密码管理数据");
    }

    /**
     * 获取账户密码管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:password:query')")
    @GetMapping(value = "/{pwdId}")
    public AjaxResult getInfo(@PathVariable("pwdId") Long pwdId)
    {
        return AjaxResult.success(zxbPasswordService.selectZxbPasswordByPwdId(pwdId));
    }

    /**
     * 新增账户密码管理
     */
    @PreAuthorize("@ss.hasPermi('system:password:add')")
    @Log(title = "账户密码管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxbPassword zxbPassword)
    {
        return toAjax(zxbPasswordService.insertZxbPassword(zxbPassword));
    }

    /**
     * 修改账户密码管理
     */
    @PreAuthorize("@ss.hasPermi('system:password:edit')")
    @Log(title = "账户密码管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZxbPassword zxbPassword)
    {
        return toAjax(zxbPasswordService.updateZxbPassword(zxbPassword));
    }

    /**
     * 删除账户密码管理
     */
    @PreAuthorize("@ss.hasPermi('system:password:remove')")
    @Log(title = "账户密码管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pwdIds}")
    public AjaxResult remove(@PathVariable Long[] pwdIds)
    {
        return toAjax(zxbPasswordService.deleteZxbPasswordByPwdIds(pwdIds));
    }
}
